const app = getApp();
import HttpRequst from '../../../utils/httpRequst.js'
import WxValidate from '../../../plugin/WxValidate'
import API from '../../../utils/config.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    zxjdArray: ['装修准备中', '硬装中', '软装中', '电器采购中', '已完成'],
    
    validateTipIsShow: false,
    sjTitle:"",
    zxjdIndex:'',
    zxjdStep:"",
    qianYueIndex:1,
    userInfo:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo: app.globalData.userInfo
    });
    this._initValidate();
   
  },

  bindPickerChange: function (e) {
    
    this.setData({
      zxjdIndex:e.detail.value,
      zxjdStep: 1+parseInt(e.detail.value)
    })
  },
  switch1Change: function (e){
    this.setData({
      qianYueIndex:e.detail.value ? 1 :0
    })
  },

  formSubmit:function(e){
    const params = e.detail.value;
    var that = this;
    if (!this.WxValidate.checkForm(e)) {
      const error = this.WxValidate.errorList[0];
      this.setData({
        validateTipMsg: error.msg,
        validateTipIsShow: true
      })
      this._validateTipHide();
    } else {
      
      wx.showLoading();
      HttpRequst(true, API.apply_biz, 1,app.getUkey(), e.detail.value, "POST", false, function (res) {
       
        if(!!res.status){
            wx.navigateTo({
              url: '/pages/index/shangJiaAddResult/shangJiaAddResult'
            })
        }else{
          wx.showToast({
            title: res.msg,
            icon: 'none'
          });
        }
        
        
      })
    }

    
  },

  //2秒后隐藏错误信息提示
  _validateTipHide: function () {
    var that = this;
    setTimeout(function () {
      that.setData({
        validateTipIsShow: false
      })
    }, 2000);
  },

  _initValidate: function () {
    const rules = {
      title: {
        required: true
      },
      sign: {
        required: true
      },
      step: {
        required: true
      },
      name: {
        required:true
      },
      mobile: {
        required:true,
        tel: true
      },
    };
    const messages = {
      title: {
        required: "请填写商家名称"
      },
      sign: {
        required: "请选择是否签约商家"
      },
      step:{
        required: "请选择装修进度"
      },
      name: {
        required: "请选择真实姓名"
      },
      mobile: {
        required: "请选择手机号码",
        tel: "请输入正确的手机号码"
      },
    };
    this.WxValidate = new WxValidate(rules, messages);
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})